package com.lin.controller;

import dto.SysRoleDto;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.RoleService;
import util.ResponseVo;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    RoleService roleService;

    @GetMapping("/list")
    public ResponseVo getRoleList(){

        return ResponseVo.ok(roleService.selectTotal());
    }

    @PostMapping("/add")
    @RequiresPermissions("role_add")
    public ResponseVo add(SysRoleDto role, Long[] menuIds) {
        return roleService.addRole(role,menuIds);
    }

    @PostMapping("/update")
    @RequiresPermissions("role_edit")
    public ResponseVo update(SysRoleDto role, Long[] menuIds) {
        return roleService.updateRole(role,menuIds);
    }

    @GetMapping("/menus")
    public ResponseVo getMenuByRole(Long id) {
        return ResponseVo.ok(roleService.findMenuByRole(id));
    }

    @PostMapping("/delete")
    @RequiresPermissions("role_delete")
    public ResponseVo deleteRole(Long roleId) {
        return roleService.deleteRole(roleId);
    }
}
